import tui from '../../common/httpRequest'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bar:60,
    navHight:40,
    tm:0,
    pd:7,
    flex:false,
    gd:0,
    tab:0,
    data:{},
    fangan:[],
    faidx:0,
    tbr:{},
    bbr:{}
  },
  updTbr(e){
    this.setData({
      tbr:e
    })
  },

  updBbr(e){
    this.setData({
      bbr:e
    })
  },
  fangan(e){
    this.setData({
      faidx:e.currentTarget.dataset.idx
    })
  },

  read(){
    wx.navigateTo({
      url: './read',
    })
  },

  call(){
    wx.makePhoneCall({
      phoneNumber: this.data.data.phone,
    })
  },

  tosel(){
    wx.navigateTo({
      url: '/pages/views/chengyuan/sel',
    })
  },

  tab(e){
    this.setData({
      tab:e.currentTarget.dataset.tab
    })
  },

  topage(e){
    wx.navigateTo({
      url: e.currentTarget.dataset.path,
    })
  },

  back(){
    wx.navigateBack()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let info = wx.getMenuButtonBoundingClientRect()
    let bar = wx.getSystemInfoSync()
    console.log(bar)
    this.setData({
      bar:bar.statusBarHeight,
      navHight:info.bottom + (info.top - bar.statusBarHeight) - bar.statusBarHeight,
      pd:bar.windowWidth - info.right,
      id:options.id
    },()=>{
      this.getDetail()
      this.getfangan()
    })
  },

  getfangan(){
    tui.request('/baoxian/api/getFangAnByPid','GET',{pid:this.data.id},false,true,true).then((res)=>{
      console.log(res.data)
      var d = res.data

      for(var i=0;i<d.length;i++){
        var dt = d[i].detail
        var json = JSON.parse(dt)
        d[i].detail = json
      }
      this.setData({
        fangan:d
      })
    })
  },

  getDetail(){
    tui.request('/baoxian/api/getProductById','GET',{id:this.data.id},false,true,true).then((res)=>{
      var d = res.data
      let xq = res.data.detail
      let lp = res.data.lipei
      d.lipei = lp.split(',')
      d.detail = xq.split(',')
      this.setData({
        data:d
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  onPageScroll(e){
    let that = this
    let st = e.scrollTop //滚动距离
    let op = 1-(1 - Math.abs(st) / 100) 

    this.setData({
      tm:op>=1?1:op<0?0:op,
    })

    let bar = wx.createSelectorQuery()
    bar.select('#tabs').boundingClientRect()
    bar.exec(function(res){
      let top = res[0].top
      if(top<=0){
        that.setData({
          flex:true
        })
      }else{
        that.setData({
          flex:false
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})